home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1037 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1000 b 

  1. Path: ornews.intel.com!news
  2. From: thurman_b_miller@ccm2.hf.intel.com (Thurman Miller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Syntax for looping through enumerated types
  5. Date: Mon, 08 Jan 1996 22:47:36 GMT
  6. Organization: Intel Corporation
  7. Message-ID: <4cs70o$8ns@ornews.intel.com>
  8. NNTP-Posting-Host: thurman-pc.ssd.intel.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Suppose I have:
  12.  
  13. enum daysoftheweek {MONDAY, TUESDAY, WEDNESDAY,THURSDAY,FRIDAY} ;
  14.  
  15. How can I loop through this using a for statement?
  16.  
  17. (the following doesn't work)
  18.  
  19. daysoftheweek nIndex;
  20. for (nIndex=MONDAY;nIndex<=FRIDAY;nIndex++)
  21. {
  22.  
  23.     switch (nIndex):
  24.     {
  25.         case  MONDAY:
  26.             doMonday();
  27.     }
  28.  
  29. }
  30.  
  31. I'd like to get away from specifying the beginning & end (ie MONDAY &
  32. TUESDAY) if possible because my enumerated list will constanty grow
  33. and I'd like to only change the definition of the enumerated list and
  34. the for statement would continue to work.
  35.  
  36. Note: This is just a trivial example, not what I'm actually wanting to
  37. do.
  38.  
  39. TIA
  40.  
  41. Thurman Miller
  42.  
  43.